<template>
	<view class="mine-coupon-list">
		<fixed>
			<tab @change="handerTabChange" :list="tabList" :activeIndex="activeIndex" :activeColor="primaryColor"
				:width="100/tabList.length + '%'" height="100rpx"></tab>
		</fixed>

		<view @tap.stop="goDetail(index)" class="fill-base mt-md ml-md mr-md pd-lg box-shadow-mini radius-16"
			v-for="(item,index) in list.data" :key="index">
			<view class="flex-between pb-lg">
				<view @tap.stop="goStore(index)" class="flex-y-center">
					<image mode="aspectFill" class="user-img radius" :src="item.source_info.avatarUrl"></image>
					<view class="flex-y-center f-paragraph c-title ml-md">下单人：<view class="text-bold max-300 ellipsis">
							{{item.source_info.nickName}}
						</view>
					</view>
				</view>
				<view class="f-paragraph c-caption" :class="[{'c-warning': item.status==1}]">
					{{statusType[item.status]}}
				</view>
			</view>
			<view class="profit-item flex-center" :class="[{'mt-md':aindex!=0}]"
				v-for="(aitem,aindex) in item.order_goods" :key="aindex">
				<image mode="aspectFill" lazy-load class="cover" :src="aitem.goods_cover">
				</image>
				<view class="flex-1 ml-md">
					<view class="f-title c-title text-bold ellipsis"> {{aitem.goods_name}} </view>
					<view class="flex-between mt-sm">
						<view class="goods-spe pl-sm pr-sm f-caption c-paragraph ellipsis radius-4"> {{aitem.spe_name}}
						</view>
						<view class="flex-1"></view>
					</view>
					<view class="flex-between mt-md f-caption c-caption">
						<view class="flex-y-baseline">
							<view class="flex-y-baseline f-icontext c-warning">¥<view class="f-sm-title text-bold">
									{{aitem.singe_pay_price}}
								</view>
							</view>
							<view class="ml-sm">提成比例 {{aitem.balance}}%</view>
						</view>
						<view>x {{aitem.num}} </view>
					</view>
				</view>
			</view>
			<view class="flex-between mt-lg pt-md b-1px-t">
				<view class="c-title ml-sm mr-sm"> 付款 ¥{{item.order_price}}</view>
				<view class="reduce-info rel flex-center pr-sm f-caption c-base" :style="{background:primaryColor}">
					<view class="reduce-tag abs flex-center pr-sm f-icontext c-title">分销佣金 </view>
					¥{{item.cash}}
				</view>
			</view>
		</view>


		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>

		<view class="space-footer"></view>

	</view>
</template>

<script>
	import {
		mapState,
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				options: {},
				statusType: {
					1: '待结算',
					2: '已结算'
				},
				activeIndex: 0,
				tabList: [{
					id: 0,
					title: '全部'
				}, {
					id: 1,
					title: '待结算'
				}, {
					id: 2,
					title: '已结算'
				}],
				param: {
					page: 1,
				},
				list: {
					data: []
				},
				loading: true,
				lockTap: false
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			userInfo: state => state.user.userInfo,
		}),
		onLoad(options) {
			this.$util.showLoading()
			this.options = options
			let {
				type = 1
			} = options
			let title = {
				1: '商城',
				2: '土地',
				3: '认养',
			}
			uni.setNavigationBarTitle({
				title: `${title[type]}订单分佣`
			})

			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return
			this.param.page = this.param.page + 1
			this.loading = true
			this.getList()
		},
		methods: {
			initIndex() {
				this.getList()
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex()
			},
			handerTabChange(index) {
				this.activeIndex = index
				this.$util.showLoading()
				this.param.page = 1
				this.list.data = []
				this.getList()
			},
			async getList() {
				let {
					list: oldList,
					tabList,
					activeIndex,
					options
				} = this
				let {
					type
				} = options
				let {
					id: status
				} = tabList[activeIndex]
				let param = Object.assign({}, this.param, {
					type,
					status
				})
				let newList = await this.$api.mine.fxOrderList(param);
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			},
			handerTabChange(index) {
				this.activeIndex = index
				this.$util.showLoading()
				this.param.page = 1
				this.list.data = []
				this.getList()
			}
		}
	}
</script>


<style lang="scss">
	.mine-coupon-list {
		.user-img {
			width: 44rpx;
			height: 44rpx;
		}

		.profit-item {
			.cover {
				width: 172rpx;
				height: 172rpx;
				border-radius: 12rpx;
			}

			.goods-spe {
				height: 44rpx;
				line-height: 44rpx;
				background: #F7F7F7;
			}

			.ellipsis {
				max-width: 458rpx;
			}
		}

		.reduce-tag {
			background: #FCC519;
			background: linear-gradient(-70deg, transparent 20rpx, #FCC519 0);
		}
	}
</style>
